pacman::p_load(sf, spNetwork, tmap, tidyverse)In-class_Ex03
Data Import and Preparation
network <- st_read(dsn="data/geospatial",
layer="Punggol_St")Reading layer `Punggol_St' from data source
`/Users/lucasluo/Desktop/SMU/Courses/Term3 Aug-Dec/ISSS626-Geospatial Analytics and Applications/lucasluo6/ISSS626/In-class-Ex/In-class_Ex03/data/geospatial'
using driver `ESRI Shapefile'
Simple feature collection with 2642 features and 2 fields
Geometry type: LINESTRING
Dimension: XY
Bounding box: xmin: 34038.56 ymin: 40941.11 xmax: 38882.85 ymax: 44801.27
Projected CRS: SVY21 / Singapore TM
childcare <- st_read(dsn="data/geospatial",
layer="Punggol_CC")Reading layer `Punggol_CC' from data source
`/Users/lucasluo/Desktop/SMU/Courses/Term3 Aug-Dec/ISSS626-Geospatial Analytics and Applications/lucasluo6/ISSS626/In-class-Ex/In-class_Ex03/data/geospatial'
using driver `ESRI Shapefile'
Simple feature collection with 61 features and 1 field
Geometry type: POINT
Dimension: XYZ
Bounding box: xmin: 34423.98 ymin: 41503.6 xmax: 37619.47 ymax: 44685.77
z_range: zmin: 0 zmax: 0
Projected CRS: SVY21 / Singapore TM
childcare_01 <-st_zm(childcare,drop = TRUE,
what = "ZM")Visualising the Geospatial Data
plot(st_geometry(network))
plot(childcare,add=T,col='red',pch = 19)
tmap_mode("view")tmap mode set to interactive viewing
tm_shape(childcare)+
tm_dots(col ="red")+
tm_shape(network)+
tm_lines()tmap_mode('plot')tmap mode set to plotting
##Preparing the lixels objects
lixels <- lixelize_lines(network,
700,
mindist = 350)
samples <- lines_center(lixels) tmap_mode('view')tmap mode set to interactive viewing
tm_shape(lixels) +
tm_lines(col = 'blue') +
tm_shape(samples) +
tm_dots() tmap_mode('plot')tmap mode set to plotting
# Performing NKDE
densities <- nkde(network,
events = childcare, # Ensure childcare is an 'sf' object
w = rep(1, nrow(childcare)), # Weights corresponding to each point in childcare
samples = samples, # Centers of lixels as samples
kernel_name = "quartic",
bw = 350,
div = "bw",
method = "simple", )visualising NKDE
samples$density <- densities
lixels$density <- densities
tmap_mode('view')
tm_shape(lixels)+
tm_lines(col="density")+
tm_shape(childcare)+
tm_dots()
tmap_mode('plot')kfun_childcare <- kfunctions(network,
childcare,
start = 0,
end = 1000,
step = 50,
width = 50,
nsim = 50,
resolution = 50,
verbose = FALSE,
conf_int = 0.05)
kfun_childcare$plotk